//package org.jeecg.modules.demo.gmslopedata.controller;
//
//
//import com.alibaba.fastjson.JSONObject;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
//import com.baomidou.mybatisplus.core.metadata.IPage;
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.beanutils.BeanUtils;
//import org.apache.shiro.SecurityUtils;
//import org.apache.shiro.authz.annotation.RequiresPermissions;
//import org.geotools.data.DataStore;
//import org.geotools.data.DataStoreFinder;
//import org.geotools.data.FeatureSource;
//import org.geotools.data.simple.SimpleFeatureCollection;
//import org.geotools.data.simple.SimpleFeatureIterator;
//import org.geotools.data.simple.SimpleFeatureSource;
//import org.geotools.filter.text.ecql.ECQL;
//import org.geotools.geometry.jts.JTS;
//import org.geotools.geometry.jts.JTSFactoryFinder;
//import org.geotools.referencing.CRS;
//import org.jeecg.common.api.dto.message.MessageDTO;
//import org.jeecg.common.api.vo.Result;
//import org.jeecg.common.aspect.annotation.AutoLog;
//import org.jeecg.common.constant.WebsocketConst;
//import org.jeecg.common.system.api.ISysBaseAPI;
//import org.jeecg.common.system.base.controller.JeecgController;
//import org.jeecg.common.system.query.QueryGenerator;
//import org.jeecg.common.system.query.QueryRuleEnum;
//import org.jeecg.common.system.vo.LoginUser;
//import org.jeecg.modules.demo.gmslopedata.entity.EvaluateCountDTO;
//import org.jeecg.modules.demo.gmslopedata.entity.GmSlopeData;
//import org.jeecg.modules.demo.gmslopedata.entity.GmSlopeDataVoScreen;
//import org.jeecg.modules.demo.gmslopedata.service.IGmSlopeDataService;
//import org.jeecg.modules.demo.gmtreatmentmeasures.entity.GmTreatmentMeasures;
//import org.jeecg.modules.demo.gmtreatmentmeasures.service.IGmTreatmentMeasuresService;
//import org.jeecg.modules.message.websocket.WebSocket;
//import org.jeecg.modules.system.entity.SysUser;
//import org.jeecg.modules.system.service.ISysUserService;
//import org.locationtech.jts.geom.Coordinate;
//import org.locationtech.jts.geom.GeometryFactory;
//import org.locationtech.jts.geom.Point;
//import org.opengis.feature.simple.SimpleFeature;
//import org.opengis.feature.simple.SimpleFeatureType;
//import org.opengis.filter.Filter;
//import org.opengis.referencing.crs.CoordinateReferenceSystem;
//import org.opengis.referencing.operation.MathTransform;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
//import org.springframework.web.bind.annotation.*;
//import org.springframework.web.servlet.ModelAndView;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.File;
//import java.lang.reflect.InvocationTargetException;
//import java.net.URL;
//import java.nio.charset.Charset;
//import java.util.*;
//import java.util.concurrent.ExecutionException;
//import java.util.concurrent.Future;
//import java.util.concurrent.atomic.AtomicInteger;
//
///**
//* @Description: 边坡数据
//* @Author: jeecg-boot
//* @Date:   2025-06-21
//* @Version: V1.0
//*/
//@Api(tags="边坡数据")
//@RestController
//@RequestMapping("/gmslopedata/gmSlopeData")
//@Slf4j
//public class GmSlopeDataController1 extends JeecgController<GmSlopeData, IGmSlopeDataService> {
//   @Autowired
//   private IGmSlopeDataService gmSlopeDataService;
//
//    @Autowired
//    private IGmTreatmentMeasuresService gmTreatmentMeasuresService;
//
//    @Autowired
//    private ISysBaseAPI sysBaseAPI;
//
//    // 注入自定义线程池
//    @Autowired
//    @Qualifier("gmDataThreadPool")
//    private ThreadPoolTaskExecutor taskExecutor;
//    @Autowired
//    private WebSocket webSocket;
//    @Autowired
//    private ISysUserService sysUserService;
//
//
//   /**
//    * 分页列表查询
//    *
//    * @param gmSlopeData
//    * @param pageNo
//    * @param pageSize
//    * @param req
//    * @return
//    */
//   //@AutoLog(value = "边坡数据-分页列表查询")
//   @ApiOperation(value="边坡数据-分页列表查询", notes="边坡数据-分页列表查询")
//   @GetMapping(value = "/list")
//   public Result<IPage<GmSlopeData>> queryPageList(GmSlopeData gmSlopeData,
//                                  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
//                                  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
//                                  HttpServletRequest req) {
//       // 自定义查询规则
//       Map<String, QueryRuleEnum> customeRuleMap = new HashMap<>();
//       // 自定义多选的查询规则为：LIKE_WITH_OR
//       customeRuleMap.put("county", QueryRuleEnum.LIKE_WITH_OR);
//       customeRuleMap.put("town", QueryRuleEnum.LIKE_WITH_OR);
//       customeRuleMap.put("village", QueryRuleEnum.LIKE_WITH_OR);
//       customeRuleMap.put("team", QueryRuleEnum.LIKE_WITH_OR);
//       customeRuleMap.put("patchNumber", QueryRuleEnum.LIKE_WITH_OR);
//       customeRuleMap.put("position", QueryRuleEnum.LIKE_WITH_OR);
//       customeRuleMap.put("threatHouse", QueryRuleEnum.LIKE_WITH_OR);
//       customeRuleMap.put("householder", QueryRuleEnum.LIKE_WITH_OR);
//       customeRuleMap.put("obligee", QueryRuleEnum.LIKE_WITH_OR);
//       QueryWrapper<GmSlopeData> queryWrapper = QueryGenerator.initQueryWrapper(gmSlopeData, req.getParameterMap(),customeRuleMap);
//       LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
//       String roleCode = sysUser.getRoleCode();
//       switch (roleCode) {
//           case  "admin":
//               break;
////			case  "user":
////				queryWrapper.eq("create_by", sysUser.getUsername());
////				break;
//           //如果是区县就查询当前曲线下的所有数据
//           case "county":
//               queryWrapper.eq("county", sysUser.getCounty());
//               break;
//           case "town":
//               queryWrapper.eq("county", sysUser.getCounty());
//               queryWrapper.eq("town", sysUser.getTown());
//               break;
//           case "village":
////				queryWrapper.eq("town", sysUser.getTown());
//               queryWrapper.eq("create_by", sysUser.getUsername());
////				queryWrapper.eq("village", sysUser.getVillage());
//               break;
//       }
//       IPage<GmSlopeData> pageList;
//
//       if (pageSize == null || pageSize <= 0) {
//           // 返回所有数据，不进行分页
//           List<GmSlopeData> list = gmSlopeDataService.list(queryWrapper);
//           // 使用一个自定义的 SimpleIPage 来包装结果（或使用 Page 的构造方法）
//           pageList = new Page<>();
//           ((Page<GmSlopeData>) pageList).setRecords(list);
//           ((Page<GmSlopeData>) pageList).setTotal(list.size());
//           ((Page<GmSlopeData>) pageList).setSize(Integer.MAX_VALUE); // 表示一次性返回所有
//           ((Page<GmSlopeData>) pageList).setCurrent(1);
//       } else {
//           // 正常分页查询
//           Page<GmSlopeData> page = new Page<>(pageNo, pageSize);
//           pageList = gmSlopeDataService.page(page, queryWrapper);
//       }
//       return Result.OK(pageList);
//   }
//
//    /**
//     * 查询大屏数据
//     *
//     * @param gmSlopeData
//     * @param req
//     * @return
//     */
//    //@AutoLog(value = "边坡数据-分页列表查询")
//    @ApiOperation(value="边坡数据-查询大屏数据", notes="边坡数据-查询大屏数据")
//    @GetMapping(value = "/listLargeScreen")
//    public Result<List<GmSlopeDataVoScreen>> listLargeScreen(GmSlopeData gmSlopeData,
//                                                              HttpServletRequest req) throws InvocationTargetException, IllegalAccessException {
//
//        QueryWrapper<GmSlopeData> queryWrapper = QueryGenerator.initQueryWrapper(gmSlopeData, req.getParameterMap());
//        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
//        String roleCode = sysUser.getRoleCode();
//        switch (roleCode) {
//            case  "admin":
//                break;
//            //如果是区县就查询当前曲线下的所有数据
//            case "county":
//                queryWrapper.eq("county", sysUser.getCounty());
//                break;
//            case "town":
//                queryWrapper.eq("county", sysUser.getCounty());
//                queryWrapper.eq("town", sysUser.getTown());
//                break;
//            case "village":
////				 queryWrapper.eq("town", sysUser.getTown());
//                queryWrapper.eq("create_by", sysUser.getUsername());
//                break;
//        }
//        if (roleCode.equals("admin")) {
//            queryWrapper.eq("village", gmSlopeData.getVillage());
//        }
//        else {
//            return Result.error("权限不足");
//        }
//        // 返回所有数据，不进行分页
//        List<GmSlopeData> list = gmSlopeDataService.list(queryWrapper);
//        //赋值数据给GmSlopeDataVoScreen
//        List<GmSlopeDataVoScreen> listScreen = new ArrayList<>();
//        for (GmSlopeData slopeData : list) {
//            GmSlopeDataVoScreen gmSlopeDataVoScreen = new GmSlopeDataVoScreen();
//            BeanUtils.copyProperties(slopeData,gmSlopeDataVoScreen);
//            listScreen.add(gmSlopeDataVoScreen);
//        }
//        return Result.OK(listScreen);
//    }
//
//    /**
//     * 分页列表申请修改记录
//     *
//     * @param gmSlopeData
//     * @param pageNo
//     * @param pageSize
//     * @param req
//     * @return
//     */
//    //@AutoLog(value = "边坡数据-分页列表查询")
//    @ApiOperation(value="边坡数据-分页列表申请修改记录", notes="边坡数据-分页列表申请修改记录")
//    @GetMapping(value = "/listUpdate")
//    public Result<IPage<GmSlopeData>> listUpdate(GmSlopeData gmSlopeData,
//                                                    @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
//                                                    @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
//                                                    HttpServletRequest req) {
//        // 自定义查询规则
//        Map<String, QueryRuleEnum> customeRuleMap = new HashMap<>();
//        // 自定义多选的查询规则为：LIKE_WITH_OR
//        customeRuleMap.put("county", QueryRuleEnum.LIKE_WITH_OR);
//        customeRuleMap.put("town", QueryRuleEnum.LIKE_WITH_OR);
//        customeRuleMap.put("village", QueryRuleEnum.LIKE_WITH_OR);
//        customeRuleMap.put("team", QueryRuleEnum.LIKE_WITH_OR);
//        customeRuleMap.put("patchNumber", QueryRuleEnum.LIKE_WITH_OR);
//        customeRuleMap.put("position", QueryRuleEnum.LIKE_WITH_OR);
//        customeRuleMap.put("threatHouse", QueryRuleEnum.LIKE_WITH_OR);
//        customeRuleMap.put("householder", QueryRuleEnum.LIKE_WITH_OR);
//        customeRuleMap.put("obligee", QueryRuleEnum.LIKE_WITH_OR);
//        QueryWrapper<GmSlopeData> queryWrapper = QueryGenerator.initQueryWrapper(gmSlopeData, req.getParameterMap(),customeRuleMap);
//        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
//        String roleCode = sysUser.getRoleCode();
//        switch (roleCode) {
//            case  "admin":
//                break;
////			case  "user":
////				queryWrapper.eq("create_by", sysUser.getUsername());
////				break;
//            //如果是区县就查询当前曲线下的所有数据
//            case "county":
//                queryWrapper.eq("county", sysUser.getCounty());
//                break;
//            case "town":
//                queryWrapper.eq("county", sysUser.getCounty());
//                queryWrapper.eq("town", sysUser.getTown());
//                break;
//            case "village":
////				 queryWrapper.eq("town", sysUser.getTown());
//                queryWrapper.eq("create_by", sysUser.getUsername());
////				queryWrapper.eq("village", sysUser.getVillage());
//                break;
//        }
//        queryWrapper.ne("is_update", "0");
//        Page<GmSlopeData> page = new Page<GmSlopeData>(pageNo, pageSize);
//        IPage<GmSlopeData> pageList = gmSlopeDataService.page(page, queryWrapper);
//
//        return Result.OK(pageList);
//    }
//
//    @ApiOperation(value="边坡数据-边坡治理方案", notes="边坡数据-边坡治理方案")
//    @GetMapping(value = "/listMeasure")
//    public Result<IPage<GmSlopeData>> listMeasure(GmSlopeData gmSlopeData,
//                                                    @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
//                                                    @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
//                                                    HttpServletRequest req) {
//        // 自定义查询规则
//        Map<String, QueryRuleEnum> customeRuleMap = new HashMap<>();
//        // 自定义多选的查询规则为：LIKE_WITH_OR
//        customeRuleMap.put("county", QueryRuleEnum.LIKE_WITH_OR);
//        customeRuleMap.put("town", QueryRuleEnum.LIKE_WITH_OR);
//        customeRuleMap.put("village", QueryRuleEnum.LIKE_WITH_OR);
//        customeRuleMap.put("team", QueryRuleEnum.LIKE_WITH_OR);
//        customeRuleMap.put("patchNumber", QueryRuleEnum.LIKE_WITH_OR);
//        customeRuleMap.put("position", QueryRuleEnum.LIKE_WITH_OR);
//        customeRuleMap.put("threatHouse", QueryRuleEnum.LIKE_WITH_OR);
//        customeRuleMap.put("householder", QueryRuleEnum.LIKE_WITH_OR);
//        customeRuleMap.put("obligee", QueryRuleEnum.LIKE_WITH_OR);
//        QueryWrapper<GmSlopeData> queryWrapper = QueryGenerator.initQueryWrapper(gmSlopeData, req.getParameterMap(),customeRuleMap);
//        //查询result字段为“较不稳定”或“不稳定”的数据
////		 queryWrapper.eq("result", "较不稳定").or().eq("result", "不稳定");
//        queryWrapper.in("result", "较不稳定", "不稳定");
//        //获取当前登录用户
//        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
//        String roleCode = sysUser.getRoleCode();
//        switch (roleCode) {
//            case  "admin":
//                break;
////			case  "user":
////				queryWrapper.eq("create_by", sysUser.getUsername());
////				break;
//            //如果是区县就查询当前曲线下的所有数据
//            case "county":
//                queryWrapper.eq("county", sysUser.getCounty());
//                break;
//            case "town":
//                queryWrapper.eq("county", sysUser.getCounty());
//                queryWrapper.eq("town", sysUser.getTown());
//                break;
//            case "village":
////				 queryWrapper.eq("town", sysUser.getTown());
//                queryWrapper.eq("create_by", sysUser.getUsername());
////				queryWrapper.eq("village", sysUser.getVillage());
//                System.out.println("roleCode = " + roleCode);
//                break;
//        }
//        Page<GmSlopeData> page = new Page<GmSlopeData>(pageNo, pageSize);
//        IPage<GmSlopeData> pageList = gmSlopeDataService.page(page, queryWrapper);
//        return Result.OK(pageList);
//    }
//
//
//    /**
//     * @param gmSlopeData
//     * @param pageNo
//     * @param pageSize
//     * @param req
//     * @return
//     */
//    @ApiOperation(value="边坡数据-分页列表查询", notes="边坡数据-分页列表查询")
//    @GetMapping(value = "/listEvaluate")
//    public Result<IPage<GmSlopeData>> queryPageListEvaluate(GmSlopeData gmSlopeData,
//                                                     @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
//                                                     @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
//                                                     HttpServletRequest req) {
//        // 自定义查询规则
//        Map<String, QueryRuleEnum> customeRuleMap = new HashMap<>();
//        // 自定义多选的查询规则为：LIKE_WITH_OR
//        customeRuleMap.put("county", QueryRuleEnum.LIKE_WITH_OR);
//        customeRuleMap.put("town", QueryRuleEnum.LIKE_WITH_OR);
//        customeRuleMap.put("village", QueryRuleEnum.LIKE_WITH_OR);
//        customeRuleMap.put("team", QueryRuleEnum.LIKE_WITH_OR);
//        customeRuleMap.put("patchNumber", QueryRuleEnum.LIKE_WITH_OR);
//        customeRuleMap.put("position", QueryRuleEnum.LIKE_WITH_OR);
//        customeRuleMap.put("threatHouse", QueryRuleEnum.LIKE_WITH_OR);
//        customeRuleMap.put("householder", QueryRuleEnum.LIKE_WITH_OR);
//        customeRuleMap.put("obligee", QueryRuleEnum.LIKE_WITH_OR);
//        QueryWrapper<GmSlopeData> queryWrapper = QueryGenerator.initQueryWrapper(gmSlopeData, req.getParameterMap(),customeRuleMap);
//
//        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
//        String roleCode = sysUser.getRoleCode();
//        switch (roleCode) {
//            case  "admin":
//                break;
////			case  "user":
////				queryWrapper.eq("create_by", sysUser.getUsername());
////				break;
//            //如果是区县就查询当前曲线下的所有数据
//            case "county":
//                queryWrapper.eq("county", sysUser.getCounty());
//                break;
//            case "town":
//                queryWrapper.eq("county", sysUser.getCounty());
//                queryWrapper.eq("town", sysUser.getTown());
//                break;
//            case "village":
//                queryWrapper.eq("create_by", sysUser.getUsername());
////				 queryWrapper.and(wrapper -> wrapper.eq("village", sysUser.getVillage())
////						 .or()
////						 .eq("create_by", sysUser.getUsername()));
//
////				queryWrapper.eq("village", sysUser.getVillage());
//                break;
//        }
//
//        //查询flag字段为1
//        queryWrapper.eq("flag", "1");
//        Page<GmSlopeData> page = new Page<GmSlopeData>(pageNo, pageSize);
//        IPage<GmSlopeData> pageList = gmSlopeDataService.page(page, queryWrapper);
////		 pageList.getRecords().forEach(item -> {
////			 System.out.println("item.getFlag() = " + item.getFlag());
////		 });
//        return Result.OK(pageList);
//    }
//    @ApiOperation(value = "边坡数据-评价结果数据统计", notes = "边坡数据-评价结果数据统计")
//    @GetMapping("/queryEvaluate")
//    public Result<Map<String, Integer>> queryEvaluate(GmSlopeData gmSlopeData, HttpServletRequest req) {
//
//        Map<String, QueryRuleEnum> customRuleMap = new HashMap<>();
//        customRuleMap.put("county", QueryRuleEnum.LIKE_WITH_OR);
//        customRuleMap.put("town", QueryRuleEnum.LIKE_WITH_OR);
//        customRuleMap.put("village", QueryRuleEnum.LIKE_WITH_OR);
//        customRuleMap.put("team", QueryRuleEnum.LIKE_WITH_OR);
//        customRuleMap.put("patchNumber", QueryRuleEnum.LIKE_WITH_OR);
//        customRuleMap.put("position", QueryRuleEnum.LIKE_WITH_OR);
//        customRuleMap.put("threatHouse", QueryRuleEnum.LIKE_WITH_OR);
//        customRuleMap.put("householder", QueryRuleEnum.LIKE_WITH_OR);
//        customRuleMap.put("obligee", QueryRuleEnum.LIKE_WITH_OR);
//        QueryWrapper<GmSlopeData> queryWrapper = QueryGenerator.initQueryWrapper(gmSlopeData, req.getParameterMap(), customRuleMap);
//
//        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
//        String roleCode = sysUser.getRoleCode();
//
//        switch (roleCode) {
//            case "county":
//                queryWrapper.eq("county", sysUser.getCounty());
//                break;
//            case "town":
//                queryWrapper.eq("county", sysUser.getCounty());
//                queryWrapper.eq("town", sysUser.getTown());
//                break;
//            case "village":
//                queryWrapper.eq("create_by", sysUser.getUsername());
//                break;
//        }
//
//        queryWrapper.eq("flag", "1");
//
//        // 3. 统计总数（使用原始条件）
//        long total = gmSlopeDataService.count(queryWrapper);
//
//        // 4. 创建分组查询（复制基础条件）
//        QueryWrapper<GmSlopeData> groupWrapper = queryWrapper.clone();
//        groupWrapper
//                .select("result", "COUNT(*) AS count") // 选择结果列和计数
//                .groupBy("result");                    // 按结果分组
//
//        // 执行查询
//        List<Map<String, Object>> resultMaps = gmSlopeDataService.listMaps(groupWrapper);
//        // 转换为 Map<result, count>
//        Map<String, Integer> statistics = new HashMap<>();
//        statistics.put("稳定", 0);
//        statistics.put("较稳定", 0);
//        statistics.put("较不稳定", 0);
//        statistics.put("不稳定", 0);
//
//        for (Map<String, Object> map : resultMaps) {
//            String result = (String) map.get("result");
//            Long count = (Long) map.get("count");
//
//            if ("稳定".equals(result)) {
//                statistics.put("稳定", count.intValue());
//            } else if ("较稳定".equals(result)) {
//                statistics.put("较稳定", count.intValue());
//            } else if ("较不稳定".equals(result)) {
//                statistics.put("较不稳定", count.intValue());
//            } else if ("不稳定".equals(result)) {
//                statistics.put("不稳定", count.intValue());
//            }
//        }
//
//        // 补充 total 数量（可选）
////		 Integer total = Math.toIntExact(gmSlopeDataService.count(queryWrapper));
//        statistics.put("total", (int) total);
//
//        return Result.OK(statistics);
//    }
//
//
//    /**
//     * 	不会进行前端条件筛选
//     * @param gmSlopeData
//     * @param req
//     * @return
//     */
//    @ApiOperation(value = "边坡数据-评价结果数据统计", notes = "边坡数据-评价结果数据统计")
//    @GetMapping("/queryEvaluate1")
//    public Result<Map<String, Integer>> queryEvaluate1(GmSlopeData gmSlopeData, HttpServletRequest req) {
//
//        Map<String, QueryRuleEnum> customRuleMap = new HashMap<>();
//        customRuleMap.put("county", QueryRuleEnum.LIKE_WITH_OR);
//        customRuleMap.put("town", QueryRuleEnum.LIKE_WITH_OR);
//        customRuleMap.put("village", QueryRuleEnum.LIKE_WITH_OR);
//        customRuleMap.put("team", QueryRuleEnum.LIKE_WITH_OR);
//        customRuleMap.put("patchNumber", QueryRuleEnum.LIKE_WITH_OR);
//        customRuleMap.put("position", QueryRuleEnum.LIKE_WITH_OR);
//        customRuleMap.put("threatHouse", QueryRuleEnum.LIKE_WITH_OR);
//        customRuleMap.put("householder", QueryRuleEnum.LIKE_WITH_OR);
//        customRuleMap.put("obligee", QueryRuleEnum.LIKE_WITH_OR);
//
//        QueryWrapper<GmSlopeData> queryWrapper = QueryGenerator.initQueryWrapper(gmSlopeData, req.getParameterMap(), customRuleMap);
//
//        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
//        String roleCode = sysUser.getRoleCode();
//
//        String county = null, town = null, createBy = null;
//        switch (roleCode) {
//            case "county":
//                county = sysUser.getCounty();
//                break;
//            case "town":
//                town = sysUser.getTown();
//                break;
//            case "village":
//                createBy = sysUser.getUsername();
//                break;
//        }
//
//        // 查询flag字段为1
//        queryWrapper.eq("flag", "1");
//
//        // 获取总数
////		 int total = (int) gmSlopeDataService.count(queryWrapper);
//
//        // 获取各状态数量
//        List<EvaluateCountDTO> dtos = gmSlopeDataService.countEvaluateResults(county, town, createBy);
//
//        Map<String, Integer> statistics = new HashMap<>();
////		 statistics.put("total", total);
//        statistics.put("稳定", 0);
//        statistics.put("较稳定", 0);
//        statistics.put("较不稳定", 0);
//        statistics.put("不稳定", 0);
//
//        for (EvaluateCountDTO dto : dtos) {
//            if ("稳定".equals(dto.getResult())) {
//                statistics.put("稳定", dto.getCount());
//            } else if ("较稳定".equals(dto.getResult())) {
//                statistics.put("较稳定", dto.getCount());
//            } else if ("较不稳定".equals(dto.getResult())) {
//                statistics.put("较不稳定", dto.getCount());
//            } else if ("不稳定".equals(dto.getResult())) {
//                statistics.put("不稳定", dto.getCount());
//            }
//        }
//        return Result.OK(statistics);
//    }
//
//
//
//
//    /**
//     * 评价结果数据统计  小数据量
//     * @param gmSlopeData
//     * @param req
//     * @return
//     */
//
//    @ApiOperation(value="边坡数据-评价结果数据统计", notes="边坡数据-评价结果数据统计")
//    @GetMapping(value = "/queryEvaluateThread")
//    public Result<Map<String, Integer>> queryEvaluateThread(GmSlopeData gmSlopeData, HttpServletRequest req) {
//         AtomicInteger stableCount = new AtomicInteger(0);
//         AtomicInteger relativelyStableCount = new AtomicInteger(0);
//         AtomicInteger relativelyUnstableCount = new AtomicInteger(0);
//         AtomicInteger unstableCount = new AtomicInteger(0);
//        // 自定义查询规则
//        Map<String, QueryRuleEnum> customeRuleMap = new HashMap<>();
//        // 自定义多选的查询规则为：LIKE_WITH_OR
//        customeRuleMap.put("county", QueryRuleEnum.LIKE_WITH_OR);
//        customeRuleMap.put("town", QueryRuleEnum.LIKE_WITH_OR);
//        customeRuleMap.put("village", QueryRuleEnum.LIKE_WITH_OR);
//        customeRuleMap.put("team", QueryRuleEnum.LIKE_WITH_OR);
//        customeRuleMap.put("patchNumber", QueryRuleEnum.LIKE_WITH_OR);
//        customeRuleMap.put("position", QueryRuleEnum.LIKE_WITH_OR);
//        customeRuleMap.put("threatHouse", QueryRuleEnum.LIKE_WITH_OR);
//        QueryWrapper<GmSlopeData> queryWrapper = QueryGenerator.initQueryWrapper(gmSlopeData, req.getParameterMap(),customeRuleMap);
//
//        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
//        String roleCode = sysUser.getRoleCode();
//        switch (roleCode) {
//            //如果是区县就查询当前曲线下的所有数据
//            case "county":
//                queryWrapper.eq("county", sysUser.getCounty());
//                break;
//            case "town":
//                queryWrapper.eq("county", sysUser.getCounty());
//                queryWrapper.eq("town", sysUser.getTown());
//                break;
//            case "village":
//                queryWrapper.eq("create_by", sysUser.getUsername());
//                break;
//        }
//        //查询flag字段为1
//        queryWrapper.eq("flag", "1");
//        List<GmSlopeData> list = gmSlopeDataService.list(queryWrapper);
//        // 添加统计信息
//        Map<String, Integer> statistics = new HashMap<>();
//        statistics.put("total", list.size());
////		 多线程获取每一条数据里面的result字段，统计每一种的个数、
//        Future<?> future = taskExecutor.submit(() -> {
//            list.forEach(item -> {
//                String status = item.getResult();
//                if ("稳定".equals(status)) {
//                    stableCount.incrementAndGet();
//                } else if ("较稳定".equals(status)) {
//                    relativelyStableCount.incrementAndGet();
//                } else if ("较不稳定".equals(status)) {
//                    relativelyUnstableCount.incrementAndGet();
//                } else if ("不稳定".equals(status)) {
//                    unstableCount.incrementAndGet();
//                }
//            });
//        });
//
//        try {
//            future.get(); // 阻塞等待任务完成
//        } catch (InterruptedException | ExecutionException e) {
//            log.error("统计任务执行失败", e);
//            return Result.error("统计失败");
//        }
//        // 构建返回结果
////		 statistics.put("total", list.size());
//        statistics.put("稳定", stableCount.get());
//        statistics.put("较稳定", relativelyStableCount.get());
//        statistics.put("较不稳定", relativelyUnstableCount.get());
//        statistics.put("不稳定", unstableCount.get());
//        return Result.OK(statistics);
//    }
//
//    //		 customeRuleMap.put("slopeType", QueryRuleEnum.LIKE_WITH_OR);
////		 customeRuleMap.put("soilLooseness", QueryRuleEnum.LIKE_WITH_OR);
////		 customeRuleMap.put("overlyingSoilType", QueryRuleEnum.LIKE_WITH_OR);
////		 customeRuleMap.put("rockCharacteristics", QueryRuleEnum.LIKE_WITH_OR);
////		 customeRuleMap.put("fractureDevelopmentDegree", QueryRuleEnum.LIKE_WITH_OR);
////		 customeRuleMap.put("cutSlopeHeight", QueryRuleEnum.LIKE_WITH_OR);
////		 customeRuleMap.put("cutSlopeGradient", QueryRuleEnum.LIKE_WITH_OR);
////		 customeRuleMap.put("cutSlopeShape", QueryRuleEnum.LIKE_WITH_OR);
////		 customeRuleMap.put("naturalSlopeGradient", QueryRuleEnum.LIKE_WITH_OR);
////		 customeRuleMap.put("vegetationCoverage", QueryRuleEnum.LIKE_WITH_OR);
////		 customeRuleMap.put("governanceMeasures", QueryRuleEnum.LIKE_WITH_OR);
////		 customeRuleMap.put("slopeWallDistance", QueryRuleEnum.LIKE_WITH_OR);
////		 customeRuleMap.put("cutSlopeWidth", QueryRuleEnum.LIKE_WITH_OR);
////		 customeRuleMap.put("cutSlopeTime", QueryRuleEnum.LIKE_WITH_OR);
////		 customeRuleMap.put("resident", QueryRuleEnum.LIKE_WITH_OR);
////		 customeRuleMap.put("threatPopulation", QueryRuleEnum.LIKE_WITH_OR);
//
//
//
//
//    /**
//     *  批量删除
//     *
//     * @param ids
//     * @return
//     */
//    @AutoLog(value = "边坡数据-根据id查询")
//    @ApiOperation(value="边坡数据-根据id查询", notes="边坡数据-根据id查询")
//    @GetMapping(value = "/selectByIds")
//    public Result<IPage<GmTreatmentMeasures>> selectByIds(@RequestParam(name="ids",required=true) String ids,
//                                                          @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
//                                                  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) {
//        Page<GmTreatmentMeasures> page = new Page<GmTreatmentMeasures>(pageNo, pageSize);
//        QueryWrapper<GmTreatmentMeasures> queryWrapper = new QueryWrapper<>();
//        queryWrapper.in("id", Arrays.asList(ids.split(",")));
//        IPage<GmTreatmentMeasures> pageList = gmTreatmentMeasuresService.page(page, queryWrapper);
//        return Result.OK(pageList);
//    }
//
//
//    @AutoLog(value = "边坡数据-根据village查询边坡个数")
//    @ApiOperation(value="边坡数据-根据village查询边坡个数", notes="边坡数据-根据village查询边坡个数")
//    @GetMapping(value = "/getSlopeCount")
//    public Result<String> getSlopeCount(@RequestParam(name="village", required = true) String village) {
//        LambdaQueryWrapper<GmSlopeData> queryWrapper = new LambdaQueryWrapper<>();
//        queryWrapper.eq(GmSlopeData::getVillage, village);
//        int count = (int) gmSlopeDataService.count(queryWrapper);
//        // 格式化为4位，不足补零
//        String formattedCount = String.format("%04d", count+1);
//        return Result.OK(formattedCount);
//    }
//
//
//   /**
//    *   添加
//    *
//    * @param gmSlopeData
//    * @return
//    */
//   @AutoLog(value = "边坡数据-添加")
//   @ApiOperation(value="边坡数据-添加", notes="边坡数据-添加")
//   @RequiresPermissions("gmslopedata:gm_slope_data:add")
//   @PostMapping(value = "/add")
//   public Result<String> add(@RequestBody GmSlopeData gmSlopeData) {
//       gmSlopeData.setIsUpdate("0");
//       gmSlopeDataService.save(gmSlopeData);
//       return Result.OK("添加成功！");
//   }
//
//
//
//
//    /**
//     *   获取评价及治理方案
//     *
//     * @param gmSlopeData
//     * @return
//     */
//    @AutoLog(value = "边坡数据-获取评价及治理方案")
//    @ApiOperation(value="边坡数据-获取评价及治理方案", notes="边坡数据-获取评价及治理方案")
//    @PostMapping(value = "/getMeasure")
//    public Result<String> getMeasure(@RequestBody GmSlopeData gmSlopeData) {
//        gmSlopeDataService.calculateYValues(gmSlopeData);
//        return Result.OK("获取评价及治理方案成功！");
//    }
//
//
//    /**
//    *  编辑
//    *
//    * @param gmSlopeData
//    * @return
//    */
//   @AutoLog(value = "边坡数据-编辑")
//   @ApiOperation(value="边坡数据-编辑", notes="边坡数据-编辑")
//   @RequiresPermissions("gmslopedata:gm_slope_data:edit")
//   @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
//   public Result<String> edit(@RequestBody GmSlopeData gmSlopeData) {
//       gmSlopeDataService.updateById(gmSlopeData);
//       return Result.OK("编辑成功!");
//   }
//
//    /**
//     *  审核
//     *
//     * @param gmSlopeData
//     * @return
//     */
//    @AutoLog(value = "边坡数据-审核")
//    @ApiOperation(value="边坡数据-审核", notes="边坡数据-审核")
//    @RequiresPermissions("gmslopedata:gm_slope_data:audit")
//    @RequestMapping(value = "/audit", method = {RequestMethod.PUT,RequestMethod.POST})
//    public Result<String> audit(@RequestBody GmSlopeData gmSlopeData) {
//        //不同意
//        if (gmSlopeData.getFlag().equals("2")){
////			 String userName = sysBaseAPI.getUserByName(gmSlopeData.getCreateBy()).getUsername();
//            MessageDTO message = new MessageDTO("系统", gmSlopeData.getCreateBy(),
//                    "重新填写采集信息",
//                    gmSlopeData.getOpinion());
//            sysBaseAPI.sendSysAnnouncement(message);
//        }else{
//            //同意
//            MessageDTO message = new MessageDTO("系统", gmSlopeData.getCreateBy(),
//                    "数据审核成功，可以去查看审核评价结果。",
//                    gmSlopeData.getOpinion());
//            sysBaseAPI.sendSysAnnouncement(message);
//            gmSlopeData.setOpinion(null);
//        }
//        gmSlopeDataService.updateById(gmSlopeData);
//        SysUser sysUser = sysUserService.getUserByName(gmSlopeData.getCreateBy());
//        JSONObject obj = new JSONObject();
//        obj.put(WebsocketConst.MSG_CMD, "audit");
//        webSocket.sendMessage(sysUser.getId(),obj.toString());
//        return Result.OK("审核完成!");
//    }
//
//
//
////	 /**
////	  *  编辑
////	  *
////	  * @param id
////	  * @return
////	  */
////	 @AutoLog(value = "边坡数据-重新上传")
////	 @ApiOperation(value="边坡数据-重新上传", notes="边坡数据-重新上传")
////	 @RequiresPermissions("gmslopedata:gm_slope_data:reUpload")
////	 @RequestMapping(value = "/reUpload", method = {RequestMethod.PUT,RequestMethod.POST})
////	 public Result<String> reUpload(@RequestParam String id) {
////		 gmSlopeDataService.update(new LambdaUpdateWrapper<GmSlopeData>()
////				 .eq(GmSlopeData::getId, id)
////				 .set(GmSlopeData::getFlag, "0"));
////		 return Result.OK("重新上传!");
////	 }
//
//    /**
//     *  编辑
//     *
//     * @param gmSlopeData
//     * @return
//     */
//    @AutoLog(value = "边坡数据-重新上传")
//    @ApiOperation(value="边坡数据-重新上传", notes="边坡数据-重新上传")
//    @RequiresPermissions("gmslopedata:gm_slope_data:reUpload")
//    @RequestMapping(value = "/reUpload", method = {RequestMethod.PUT,RequestMethod.POST})
//    public Result<String> reUpload(@RequestBody GmSlopeData gmSlopeData) {
//        gmSlopeDataService.updateById(gmSlopeData);
////		 JSONObject obj = new JSONObject();
////		 obj.put(WebsocketConst.MSG_CMD, "update");
////		 webSocket.sendMessage(obj.toString());
//        return Result.OK("重新上传!");
//    }
//
//    /**
//     *  申请修改
//     *
//     * @param gmSlopeData
//     * @return
//     */
//    @AutoLog(value = "边坡数据-申请修改")
//    @ApiOperation(value="边坡数据-申请修改", notes="边坡数据-申请修改")
//    @RequiresPermissions("gmslopedata:gm_slope_data:revise")
//    @RequestMapping(value = "/revise", method = RequestMethod.POST)
//    public Result<String> revise(@RequestBody GmSlopeData gmSlopeData) {
//        String id = gmSlopeData.getId();
//        gmSlopeDataService.update(new LambdaUpdateWrapper<GmSlopeData>()
//                .eq(GmSlopeData::getId, id)
//                .set(GmSlopeData::getIsUpdate, "1")
//                .set(GmSlopeData::getApplicationContent, gmSlopeData.getApplicationContent())
//        );
////		 String userName = sysBaseAPI.getUserByName(gmSlopeData.getCreateBy()).getUsername();
////		 MessageDTO message = new MessageDTO("系统", userName,
////		          "申请修改数据，请及时处理。",
////		          gmSlopeData.getOpinion());
////		 JSONObject obj = new JSONObject();
////		 obj.put(WebsocketConst.MSG_CMD, "update");
////		 webSocket.sendMessage(obj.toString());
//        return Result.OK("申请修改!");
//    }
//
//    /**
//     *  处理申请修改
//     *
//     * @param gmSlopeData
//     * @return
//     */
//    @AutoLog(value = "边坡数据-处理申请修改")
//    @ApiOperation(value="边坡数据-处理申请修改", notes="边坡数据-处理申请修改")
////	 @RequiresPermissions("gmslopedata:gm_slope_data:handlerRevise")
//    @RequestMapping(value = "/handlerRevise", method = RequestMethod.POST)
//    public Result<String> handlerRevise(@RequestBody GmSlopeData gmSlopeData) {
//        String handlerUpdate = gmSlopeData.getIsUpdate();
//        if (handlerUpdate.equals("2")){
//            MessageDTO message = new MessageDTO("系统", gmSlopeData.getCreateBy(),
//                    "同意申请修改数据，请及时修改数据。",
//                    gmSlopeData.getOpinion());
//            sysBaseAPI.sendSysAnnouncement(message);
////			 gmSlopeData.setUpdateOpinion(null);
//        }else if (handlerUpdate.equals("3")){
//            MessageDTO message = new MessageDTO("系统", gmSlopeData.getCreateBy(),
//                    "拒绝申请修改数据!",
//                    gmSlopeData.getOpinion());
//            sysBaseAPI.sendSysAnnouncement(message);
//        }
//        gmSlopeDataService.updateById(gmSlopeData);
//        SysUser sysUser = sysUserService.getUserByName(gmSlopeData.getCreateBy());
//        JSONObject obj = new JSONObject();
//        obj.put(WebsocketConst.MSG_CMD, "handlerRevise");
//        webSocket.sendMessage(sysUser.getId(),obj.toString());
//        return Result.OK("申请修改!");
//    }
//
//   /**
//    *   通过id删除
//    *
//    * @param id
//    * @return
//    */
//   @AutoLog(value = "边坡数据-通过id删除")
//   @ApiOperation(value="边坡数据-通过id删除", notes="边坡数据-通过id删除")
//   @RequiresPermissions("gmslopedata:gm_slope_data:delete")
//   @DeleteMapping(value = "/delete")
//   public Result<String> delete(@RequestParam(name="id",required=true) String id) {
//       gmSlopeDataService.removeById(id);
//       return Result.OK("删除成功!");
//   }
//
//   /**
//    *  批量删除
//    *
//    * @param ids
//    * @return
//    */
//   @AutoLog(value = "边坡数据-批量删除")
//   @ApiOperation(value="边坡数据-批量删除", notes="边坡数据-批量删除")
//   @RequiresPermissions("gmslopedata:gm_slope_data:deleteBatch")
//   @DeleteMapping(value = "/deleteBatch")
//   public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
//       this.gmSlopeDataService.removeByIds(Arrays.asList(ids.split(",")));
//       return Result.OK("批量删除成功!");
//   }
//
//   /**
//    * 通过id查询
//    *
//    * @param id
//    * @return
//    */
//   //@AutoLog(value = "边坡数据-通过id查询")
//   @ApiOperation(value="边坡数据-通过id查询", notes="边坡数据-通过id查询")
//   @GetMapping(value = "/queryById")
//   public Result<GmSlopeData> queryById(@RequestParam(name="id",required=true) String id) {
//       GmSlopeData gmSlopeData = gmSlopeDataService.getById(id);
//       if(gmSlopeData==null) {
//           return Result.error("未找到对应数据");
//       }
//       return Result.OK(gmSlopeData);
//   }
//
//
//   /**
//   * 导出excel
//   *
//   * @param request
//   * @param gmSlopeData
//   */
//   @RequiresPermissions("gmslopedata:gm_slope_data:exportXls")
//   @RequestMapping(value = "/exportXls")
//   public ModelAndView exportXls(HttpServletRequest request, GmSlopeData gmSlopeData) {
//       return super.exportXls(request, gmSlopeData, GmSlopeData.class, "边坡数据");
//   }
//
//   /**
//     * 通过excel导入数据
//   *
//   * @param request
//   * @param response
//   * @return
//   */
//   @RequiresPermissions("gmslopedata:gm_slope_data:importExcel")
//   @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
//   public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
//       return super.importExcel(request, response, GmSlopeData.class);
//   }
//
//
//    /**
//     * 通过excel导入数据
//     *
//     * @param request
//     * @param response
//     * @return
//     */
//    @RequiresPermissions("gmslopedata:gm_slope_data:importExcel")
//    @RequestMapping(value = "/importExcelCustom", method = RequestMethod.POST)
//    public Result<?> importExcelCustom(HttpServletRequest request, HttpServletResponse response) {
//        return gmSlopeDataService.importExcelCustom(request, response, GmSlopeData.class);
//    }
//
//    // 引入模板文件存放地址
//    @Value(value = "${gm.template-file}")
//    private String templateLeaveApprovalFile;
//
//    /**
//     * 导出审批意见Word(模板)
//     * templateLeaveApprovalFile为模板存放路径，请在yml文件中配置
//     * @param request
//     * @param id
//     */
//    @ApiOperation(value="exportWord", notes="exportWord")
//    @GetMapping(value = "/exportWord")
//    public ModelAndView exportWord(HttpServletRequest request, @RequestParam(name="id",required=false) String id) {
//        return gmSlopeDataService.exportWord(id, templateLeaveApprovalFile);
//    }
//    /**
//     * 导出审批意见Word(模板)
//     * templateLeaveApprovalFile为模板存放路径，请在yml文件中配置
//     * @param id
//     */
//    @ApiOperation(value="exportWord", notes="exportWord")
//    @GetMapping(value = "/exportWord1")
//    public Result<byte[]> exportWord1( @RequestParam(name="id",required=false) String id) {
//        return Result.ok(gmSlopeDataService.exportWord1(id, templateLeaveApprovalFile));
//    }
//
//    // 引入模板文件存放地址
//    @Value(value = "${gm.SockType}")
//    private String SockTypePath;
//    // 引入模板文件存放地址
//    @Value(value = "${gm.GeoType}")
//    private String GeoTypePath;
//
//
//
//
//
//
//
//
//    @ApiOperation(value="查询岩组类型", notes="查询岩组类型")
//    @PostMapping("/selectSockType1")
//    public Result<Map<String, Object>> queryByPoint1(@RequestBody JSONObject jsonObject) throws Exception {
//
//        double longitude = jsonObject.getDouble("longitude");
//        System.out.println("longitude = " + longitude);
//        double latitude = jsonObject.getDouble("latitude");
//        System.out.println("latitude = " + latitude);
//        Map<String, Object> result = new HashMap<>();
//        result.put("status", "success");
//
//        // 设置字符编码为 GBK/GB18030，避免 DBF 文件中中文乱码
//        System.setProperty("org.geotools.referencing.forceXY", "true");
//        Charset charset = Charset.forName("GBK"); // 或 GB18030
//        System.setProperty("dbf.encoding", charset.name());
//
//        File file = new File(SockTypePath);
//        if (!file.exists()) {
//            result.put("error", "文件不存在");
//            result.put("status", "fail");
//            return  Result.ok(result) ;
//        }
//
//        Map<String, Object> map = new HashMap<>();
//        map.put("url", file.toURI().toURL());
//        map.put("charset", charset);
//
//        DataStore dataStore = null;
//        try {
//            dataStore = DataStoreFinder.getDataStore(map);
//            if (dataStore == null) {
//                result.put("error", "无法加载数据源，请检查路径和编码");
//                result.put("status", "fail");
//                return  Result.ok(result) ;
//            }
//
//            String typeName = dataStore.getTypeNames()[0];
//            SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
//            SimpleFeatureType schema = featureSource.getSchema();
//
//            // 打印 CRS 信息（调试）
//            CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:4326");
//            CoordinateReferenceSystem targetCRS = schema.getCoordinateReferenceSystem();
//            MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS, true);
//
//            GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
//            Point point = geometryFactory.createPoint(new Coordinate(longitude, latitude));
//            Point transformedPoint = (Point) JTS.transform(point, transform);
//
//            String filterStr = "INTERSECTS(the_geom, POINT(" + transformedPoint.getX() + " " + transformedPoint.getY() + "))";
//            Filter filter = ECQL.toFilter(filterStr);
//
//            SimpleFeatureCollection features = featureSource.getFeatures(filter);
//            List<Map<String, Object>> matchedFeatures = new ArrayList<>();
//
//            try (SimpleFeatureIterator iterator = features.features()) {
//                while (iterator.hasNext()) {
//                    SimpleFeature feature = iterator.next();
//
//                    // 获取字段值
//                    Object rockType = feature.getAttribute("岩类");
//                    Object rockTypeName = feature.getAttribute("岩类名称");
////					 Object descriptor = feature.getAttribute("DESCRIPTOR");
////					 Object symbol = feature.getAttribute("SYMBOL");
//
//
//                    System.out.println("岩类: " + (rockType != null ? rockType.toString() : "null"));
//                    System.out.println("岩类名称: " + (rockTypeName != null ? rockTypeName.toString() : "null"));
//
//                    // 拼接两个值
//                    String combinedValue = "";
//                    if (rockType != null && rockTypeName != null) {
//                        combinedValue = rockType.toString() + " " + rockTypeName.toString();
//                    } else if (rockType != null) {
//                        combinedValue = rockType.toString();
//                    } else if (rockTypeName != null) {
//                        combinedValue = rockTypeName.toString();
//                    }
//
//                    // 添加到结果中
//                    matchedFeatures.add(Collections.singletonMap("岩组类型", combinedValue));
//                }
//            }
//
//
//            result.put("features", matchedFeatures);
//
//        } catch (Exception e) {
//            result.put("error", e.getMessage());
//            result.put("status", "fail");
//            e.printStackTrace();
//        } finally {
//            if (dataStore != null) {
//                dataStore.dispose();
//            }
//        }
//
//        return  Result.ok(result) ;
//    }
//
//
//
//    private static final Map<String, DataStore> dataStoreCache = new HashMap<>();
//    @ApiOperation(value = "查询岩组类型", notes = "根据坐标点查询岩组类型")
//    @PostMapping("/selectSockType")
//    public Result<Map<String, Object>>selectSockType(@RequestBody JSONObject jsonObject) {
//        double longitude = jsonObject.getDouble("longitude");
//        double latitude = jsonObject.getDouble("latitude");
//
//        Map<String, Object> result = new HashMap<>();
//
//
//        // 设置全局参数（只需设置一次）
//        System.setProperty("org.geotools.referencing.forceXY", "true");
//        System.setProperty("dbf.encoding", "GBK");
//
//        try {
//
//            // 2. 查询坡度数据
//            Map<String, Object> slopeResult = queryShapefile(
//                    SockTypePath,
//                    longitude,
//                    latitude,
//                    new String[]{"岩类", "岩类名称"},
//                    "rockType"
//            );
//
//            result.putAll(slopeResult);
//
//        } catch (Exception e) {
//            result.put("status", "fail");
//            result.put("error", e.getMessage());
//            e.printStackTrace();
//        }
//
//        return Result.ok(result);
//    }
//    @ApiOperation(value = "查询坡度类型", notes = "查询坡度类型")
//    @PostMapping("/selectGeoType")
//    public Result<Map<String, Object>>selectGeoType(@RequestBody JSONObject jsonObject) {
//        double longitude = jsonObject.getDouble("longitude");
//        double latitude = jsonObject.getDouble("latitude");
//
//        Map<String, Object> result = new HashMap<>();
//
//        // 设置全局参数（只需设置一次）
//        System.setProperty("org.geotools.referencing.forceXY", "true");
//        System.setProperty("dbf.encoding", "GBK");
//
//        try {
//
//            // 2. 查询坡度数据
//            Map<String, Object> slopeResult = queryShapefile(
//                    GeoTypePath,
//                    longitude,
//                    latitude,
//                    new String[]{"gridcode"},  // 根据实际字段名调整
//                    "slope"
//            );
//
//            result.putAll(slopeResult);
//
//        } catch (Exception e) {
//            result.put("status", "fail");
//            result.put("error", e.getMessage());
//            e.printStackTrace();
//        }
//
//        return Result.ok(result);
//    }
//    @ApiOperation(value = "查询岩组类型和地形坡度", notes = "根据坐标点查询岩组类型和地形坡度")
//    @PostMapping("/selectGeoData")
//    public Result<Map<String, Object>>queryGeoData(@RequestBody JSONObject jsonObject) {
//        double longitude = jsonObject.getDouble("longitude");
//        double latitude = jsonObject.getDouble("latitude");
//
//        Map<String, Object> result = new HashMap<>();
//
//        // 设置全局参数（只需设置一次）
//        System.setProperty("org.geotools.referencing.forceXY", "true");
//        System.setProperty("dbf.encoding", "GBK");
//        log.info("longitude: {}, latitude: {}", longitude, latitude);
//
//        try {
//            // 1. 查询岩组数据
//            Map<String, Object> rockTypeFuture =  queryShapefile(
//                            SockTypePath,
//                            longitude,
//                            latitude,
//                            new String[]{"岩类", "岩类名称"},
//                            "rockType"
//                    );
//
//            // 2. 查询坡度数据
//       Map<String, Object> slopeFuture =  queryShapefile(
//                            GeoTypePath,
//                            longitude,
//                            latitude,
//                            new String[]{"gridcode"},  // 根据实际字段名调整
//                            "slope"
//                    );
//
//            // 合并结果
//            result.putAll(rockTypeFuture);
//            result.putAll(slopeFuture);
//        } catch (Exception e) {
//            result.put("status", "fail");
//            result.put("error", e.getMessage());
//            e.printStackTrace();
//        }
//        return Result.ok(result);
//    }
//
//
//
//    @ApiOperation(value = "查询岩组类型和地形坡度", notes = "根据坐标点查询岩组类型和地形坡度")
//    @PostMapping("/selectGeoData1")
//    public Result<Map<String, Object>>queryGeoData1(@RequestBody JSONObject jsonObject) {
//        double longitude = jsonObject.getDouble("longitude");
//        double latitude = jsonObject.getDouble("latitude");
//
//        Map<String, Object> result = new HashMap<>();
//
//        // 设置全局参数（只需设置一次）
//        System.setProperty("org.geotools.referencing.forceXY", "true");
//        System.setProperty("dbf.encoding", "GBK");
//        log.info("longitude: {}, latitude: {}", longitude, latitude);
//
//        try {
//            // 1. 查询岩组数据
//            Future<Map<String, Object>> rockTypeFuture = taskExecutor.submit(() -> {
//                try {
//                    return queryShapefile(
//                            SockTypePath,
//                            longitude,
//                            latitude,
//                            new String[]{"岩类", "岩类名称"},
//                            "rockType"
//                    );
//                } catch (Exception e) {
//                    throw new RuntimeException(e);
//                }
//            });
//            // 2. 查询坡度数据
//            Future<Map<String, Object>> slopeFuture = taskExecutor.submit(() -> {
//                try {
//                    return queryShapefile(
//                            GeoTypePath,
//                            longitude,
//                            latitude,
//                            new String[]{"gridcode"},  // 根据实际字段名调整
//                            "slope"
//                    );
//                } catch (Exception e) {
//                    throw new RuntimeException(e);
//                }
//            });
//            // 合并结果
//            result.putAll(rockTypeFuture.get());
//            result.putAll(slopeFuture.get());
//        } catch (Exception e) {
//            result.put("status", "fail");
//            result.put("error", e.getMessage());
//            e.printStackTrace();
//        }
//        return Result.ok(result);
//    }
//
//    /**
//     * 通用Shapefile查询方法
//     *
//     * @param filePath Shapefile路径
//     * @param longitude 经度
//     * @param latitude 纬度
//     * @param attributeNames 需要查询的属性字段名
//     * @param resultKey 结果中使用的键名
//     * @return 包含查询结果的Map
//     */
//    private Map<String, Object> queryShapefile(String filePath, double longitude, double latitude,
//                                               String[] attributeNames, String resultKey)
//            throws Exception {
//        log.info("filePath: {}, longitude: {}, latitude: {}", filePath, longitude, latitude);
//
//        Map<String, Object> result = new HashMap<>();
//        List<Map<String, String>> featuresList = new ArrayList<>();
//
//        File file = new File(filePath);
//        if (!file.exists()) {
//            result.put(resultKey + "_error", "文件不存在: " + filePath);
//            return result;
//        }
//
//        DataStore dataStore = getDataStore(file.toURI().toURL(), "GBK");
//        if (dataStore == null) {
//            result.put(resultKey + "_error", "无法加载数据源: " + filePath);
//            return result;
//        }
//        log.info("dataStore: {}", dataStore);
//
//        String typeName = dataStore.getTypeNames()[0];
//        FeatureSource featureSource = dataStore.getFeatureSource(typeName);
//        SimpleFeatureType schema = (SimpleFeatureType) featureSource.getSchema();
//
//        // 坐标系转换 (WGS84 -> 数据源CRS)
//        CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:4326");
//        CoordinateReferenceSystem targetCRS = schema.getCoordinateReferenceSystem();
//        MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS, true);
//
//        // 创建查询点
//        GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
//        Point point = geometryFactory.createPoint(new Coordinate(longitude, latitude));
//        Point transformedPoint = (Point) JTS.transform(point, transform);
//
//        // 构建空间查询过滤器
//        Filter filter = ECQL.toFilter(
//                "INTERSECTS(the_geom, POINT(" + transformedPoint.getX() + " " + transformedPoint.getY() + "))"
//        );
//
//        // 执行查询
//        SimpleFeatureCollection features = (SimpleFeatureCollection) featureSource.getFeatures(filter);
//        try (SimpleFeatureIterator iterator = features.features()) {
//            while (iterator.hasNext()) {
//                SimpleFeature feature = iterator.next();
//                Map<String, String> attributeMap = new HashMap<>();
//
//                // 提取所需属性
//                for (String attrName : attributeNames) {
//                    Object value = feature.getAttribute(attrName);
//                    attributeMap.put(attrName, value != null ? value.toString() : "N/A");
//                }
//                featuresList.add(attributeMap);
//            }
//        }
//
//        // 特殊处理：岩组数据拼接字段
//        if ("rockType".equals(resultKey)) {
//           String combinedValues = "";
//            for (Map<String, String> attrs : featuresList) {
//                String rockType = attrs.getOrDefault("岩类", "");
//                String rockTypeName = attrs.getOrDefault("岩类名称", "");
//                combinedValues=rockType + " " + rockTypeName.trim();
//            }
//            result.put(resultKey, combinedValues);
//        }
//        // 坡度数据直接返回数值
//        else if ("slope".equals(resultKey) && !featuresList.isEmpty()) {
//            // 取第一个匹配要素的值（假设点只落在一个坡度区间）
//            String slopeValue = featuresList.get(0).get("gridcode");
//            try {
//                if(slopeValue.equals("1")){
//                    result.put(resultKey, "A 小于20°".trim());
//                }else if(slopeValue.equals("2")){
//                    result.put(resultKey, "B 20°-30°".trim());
//                }else {
//                    result.put(resultKey, "C 大于30°".trim());
//                }
//            } catch (NumberFormatException e) {
//                result.put(resultKey, slopeValue); // 保留原始字符串值
//            }
//        } else {
//            result.put(resultKey, featuresList);
//        }
//
//        return result;
//    }
//
//    private synchronized DataStore getDataStore(URL url, String charset) throws Exception {
//        String cacheKey = url.toString();
//        if (dataStoreCache.containsKey(cacheKey)) {
//            return dataStoreCache.get(cacheKey);
//        }
//
//        // 准备数据存储参数
//        Map<String, Object> params = new HashMap<>();
//        params.put("url", url);
//        params.put("charset", charset);
//
//        DataStore dataStore = DataStoreFinder.getDataStore(params);
//        if (dataStore != null) {
//            dataStoreCache.put(cacheKey, dataStore);
//        }
//
//        return dataStore;
//    }
//
//
//
//
//
//
//
////	 @PostMapping("/query1")
////	 public Map<String, Object> querySlope2(@RequestBody JSONObject jsonObject) {
////		 Map<String, Object> result = new HashMap<>();
////		 // 1. 提取经纬度（默认使用赣州测试坐标）
////		 double longitude = (double) jsonObject.getOrDefault("longitude", 114.691366);
////		 double latitude = (double) jsonObject.getOrDefault("latitude", 25.753217);
////
////		 // 2. 加载坡度TIF文件（从classpath的shapefiles目录）
////		 URL slopeTifUrl = getClass().getClassLoader().getResource("shapefiles/赣州市地形坡度.tif");
////		 if (slopeTifUrl == null) {
////			 result.put("status", "fail");
////			 result.put("error", "坡度TIF文件（赣州市地形坡度.tif）未找到");
////			 return result;
////		 }
////
////		 try {
////			 // 3. 获取ImageReader并读取基础信息
////			 Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("tiff");
////			 if (!readers.hasNext()) {
////				 result.put("status", "fail");
////				 result.put("error", "未找到Tiff图片读取器");
////				 return result;
////			 }
////			 ImageReader imageReader = readers.next();
////
////			 try (ImageInputStream input = ImageIO.createImageInputStream(slopeTifUrl.openStream())) {
////				 imageReader.setInput(input);
////				 System.out.println("imageReader = " + imageReader);
////
////				 // 获取图像总尺寸（栅格行列数）
////				 int gridWidth = imageReader.getWidth(0);
////				 int gridHeight = imageReader.getHeight(0);
////				 System.out.println("gridWidth = " + gridWidth);
////				 System.out.println("gridHeight = " + gridHeight);
////
////				 // 获取瓦片尺寸（分块大小）
////				 int tileWidth = 128;
////
////				 int tileHeight = 128;
////
////				 // 4. 读取TFW文件的6个仿射变换参数
////				 double[] tfwParams = readTfwFile("shapefiles/赣州市地形坡度.tfw");
////				 double a = tfwParams[0]; // X方向像元大小
////				 double e = tfwParams[3]; // Y方向像元大小（通常为负）
////				 double c = tfwParams[4]; // 栅格左上角X坐标
////				 double f = tfwParams[5]; // 栅格左上角Y坐标
////
////				 // 5. 计算经纬度对应的栅格行列号
////				 double colDouble = (longitude - c) / a - 0.5; // 像元中心偏移修正
////				 double rowDouble = (latitude - f) / e - 0.5;   // 像元中心偏移修正
////				 int col = (int) Math.round(colDouble);
////				 int row = (int) Math.round(rowDouble);
////
////				 // 6. 检查行列号是否越界
////				 if (col < 0 || col >= gridWidth || row < 0 || row >= gridHeight) {
////					 result.put("status", "fail");
////					 result.put("error", "经纬度点对应的栅格行列号超出范围");
////					 return result;
////				 }
////
////				 // 7. 计算目标点所在的分块（Tile）索引及内部偏移
////				 int tileCol = col / tileWidth;
////				 int tileRow = row / tileHeight;
////				 int x = tileCol * tileWidth;          // 分块起始列
////				 int y = tileRow * tileHeight;         // 分块起始行
////				 int readWidth = Math.min(tileWidth, gridWidth - x);  // 防止越界
////				 int readHeight = Math.min(tileHeight, gridHeight - y);
////
////				 // 8. 计算分块内偏移坐标（相对分块起点）
////				 int tileInnerCol = col - x;
////				 int tileInnerRow = row - y;
////
////				 // 9. 设置读取区域为当前分块
////				 Rectangle sourceRegion = new Rectangle(x, y, readWidth, readHeight);
////				 ImageReadParam param = imageReader.getDefaultReadParam();
////				 param.setSourceRegion(sourceRegion);
////
////				 // 10. 读取分块数据
////				 BufferedImage tileImage = imageReader.read(0, param);
////				 Raster raster = tileImage.getRaster();
////
////				 // 11. 获取目标像素的坡度值（单波段）
////				 int band = 0;
////				 double slopeValue = raster.getSampleDouble(tileInnerCol, tileInnerRow, band);
////
////				 result.put("status", "success");
////				 result.put("slope", slopeValue);
////
////			 } finally {
////				 imageReader.dispose();
////			 }
////		 } catch (IOException e) {
////			 result.put("status", "fail");
////			 result.put("error", "处理坡度数据时出错：" + e.getMessage());
////			 e.printStackTrace();
////		 }
////
////		 return result;
////	 }
////
////
////
////
////
////
////
////	 /**
////	  * 工具方法：从classpath读取.tfw文件，解析6个仿射变换参数
////	  * @param resourcePath classpath下的资源路径（如 "shapefiles/赣州市地形坡度.tfw"）
////	  * @return 长度为6的double数组，顺序为 [a, d, b, e, c, f]
////	  */
////	 private double[] readTfwFile(String resourcePath) throws IOException {
////		 double[] params = new double[6];
////		 // 从classpath读取资源流，避免中文路径编码问题
////		 try (InputStream is = getClass().getClassLoader().getResourceAsStream(resourcePath);
////			  BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
////			 String line;
////			 int index = 0;
////			 while ((line = br.readLine()) != null && index < 6) {
////				 params[index] = Double.parseDouble(line.trim());
////				 index++;
////			 }
////		 }
////		 return params;
////	 }
////
////	 /**
////	  * 工具方法：读取.prj文件，解析为CoordinateReferenceSystem（投影基准）
////	  * @param resourcePath classpath路径（如 "shapefiles/赣州市dem.prj"）
////	  */
////	 private CoordinateReferenceSystem readPrjFile(String resourcePath) throws IOException, FactoryException {
////		 try (InputStream is = getClass().getClassLoader().getResourceAsStream(resourcePath);
////			  BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
////			 // 合并PRJ文件的WKT行（可能多行）
////			 String wkt = br.lines().collect(Collectors.joining());
////			 return CRS.parseWKT(wkt);
////		 }
////	 }
////
////
////	 @ApiOperation(value = "单独测试地形坡度查询", notes = "仅返回经纬度对应的地形坡度值")
////	 @PostMapping("/querySlope1")
////	 public Map<String, Object> querySlope1(@RequestBody JSONObject jsonObject) {
////		 Map<String, Object> result = new HashMap<>();
////		 // 1. 提取经纬度（默认使用测试坐标）
////		 double longitude = (double) jsonObject.getOrDefault("longitude", 114.691366);
////		 double latitude = (double) jsonObject.getOrDefault("latitude", 25.753217);
////
////		 // 2. 加载坡度TIF文件（从classpath的shapefiles目录）
////		 URL slopeTifUrl = getClass().getClassLoader().getResource("shapefiles/赣州市地形坡度.tif");
////		 if (slopeTifUrl == null) {
////			 result.put("status", "fail");
////			 result.put("error", "坡度数据文件（赣州市地形坡度.tif）未找到");
////			 return result;
////		 }
////
////		 GeoTiffReader slopeReader = null;
////		 try {
////			 slopeReader = new GeoTiffReader(slopeTifUrl);
////
////			 // 3. 读取栅格元数据（CRS、空间范围、栅格几何）
////			 GridCoverage2D slopeCoverage = slopeReader.read(null);
////			 CoordinateReferenceSystem slopeCRS = slopeCoverage.getCoordinateReferenceSystem();
////			 org.opengis.geometry.Envelope slopeEnvelope = slopeCoverage.getEnvelope();
////			 GridGeometry2D gridGeometry = slopeCoverage.getGridGeometry();
////
////			 // 4. 坐标转换：WGS84经纬度（EPSG:4326）→ 坡度TIF的CRS
////			 CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:4326");
////			 MathTransform transform = CRS.findMathTransform(sourceCRS, slopeCRS, true);
////			 GeometryFactory geometryFactory = new GeometryFactory();
////			 Point inputPoint = geometryFactory.createPoint(new Coordinate(longitude, latitude));
////			 Point slopePoint = (Point) JTS.transform(inputPoint, transform);
////			 double x = slopePoint.getX();
////			 double y = slopePoint.getY();
////
////			 // 5. 检查点是否在坡度栅格范围内
//////			 if (!slopeEnvelope.contains(x, y)) {
//////				 result.put("status", "fail");
//////				 result.put("error", "经纬度点不在坡度数据的空间范围内");
//////				 return result;
//////			 }
////
////			 // 6. 计算栅格行列号（含像元中心偏移修正）
////			 java.awt.geom.AffineTransform gridToCRS = (java.awt.geom.AffineTransform) gridGeometry.getGridToCRS();
////			 double cellWidth = Math.abs(gridToCRS.getScaleX());   // 像元宽度
////			 double cellHeight = Math.abs(gridToCRS.getScaleY());  // 像元高度
////			 double minX = slopeEnvelope.getMinimum(0);            // 栅格空间范围最小X
////			 double maxY = slopeEnvelope.getMaximum(1);            // 栅格空间范围最大Y
////
////			 // 像元中心偏移：地理坐标转行列号时，需减去0.5（栅格原点在像元中心）
////			 double colDouble = (x - minX) / cellWidth - 0.5;
////			 double rowDouble = (maxY - y) / cellHeight - 0.5;
////			 int col = (int) Math.round(colDouble);
////			 int row = (int) Math.round(rowDouble);
////			 System.out.println("col = " + col);
////			 System.out.println("row = " + row);
////
////			 // 7. 检查行列号是否越界
////			 java.awt.Rectangle gridRange = gridGeometry.getGridRange2D();
////			 System.out.println(gridRange.getWidth());
////			 System.out.println(gridRange.getHeight());
////			 System.out.println("gridRange.width = " + gridRange.width);
////			 System.out.println("gridRange.height = " + gridRange.height);
//////			 if (col < 0 || col >= gridRange.width || row < 0 || row >= gridRange.height) {
//////				 result.put("status", "fail");
//////				 result.put("error", "经纬度点对应的栅格行列号超出范围");
//////				 return result;
//////			 }
////
////			 // 8. 读取目标像元的坡度值（单波段假设）
////			 RenderedImage renderedImage = slopeCoverage.getRenderedImage();
////			 System.out.println("renderedImage = " + renderedImage);
////
////			 Raster raster = slopeCoverage.getRenderedImage().getData();
////			 double[] pixelValues = new double[1]; // 单波段，数组长度为1
////			 raster.getPixel(col, row, pixelValues);
////			 double slopeValue = pixelValues[0];
////
////			 result.put("status", "success");
////			 result.put("slope", slopeValue);
////
////		 } catch (FactoryException | TransformException | java.io.IOException e) {
////			 result.put("status", "fail");
////			 result.put("error", "处理坡度数据时出错：" + e.getMessage());
////			 e.printStackTrace();
////		 } finally {
////			 if (slopeReader != null) {
////				 slopeReader.dispose(); // 释放资源
////			 }
////		 }
////
////		 return result;
////	 }
////
////
////	 @ApiOperation(value = "单独测试地形坡度查询", notes = "仅返回经纬度对应的地形坡度值")
////	 @PostMapping("/querySlope4")
////	 public Map<String, Object> querySlope4(@RequestBody JSONObject jsonObject) throws IOException {
////		 Map<String, Object> result = new HashMap<>();
////		 // 1. 提取经纬度（默认赣州测试坐标：114.691366, 25.753217）
////		 double longitude = (double) jsonObject.getOrDefault("longitude", 114.691366);
////		 double latitude = (double) jsonObject.getOrDefault("latitude", 25.753217);
////
////		 // 2. 加载地形坡度TIF（classpath:shapefiles/赣州市地形坡度.tif）
////		 URL slopeTifUrl = getClass().getClassLoader().getResource("shapefiles/赣州市地形坡度.tif");
////		 if (slopeTifUrl == null) {
////			 result.put("status", "fail");
////			 result.put("error", "坡度文件未找到！检查：①文件是否在resource/shapefiles下 ②文件名是否为「赣州市地形坡度.tif」");
////			 return result;
////		 }
////
////		 GridCoverageReader slopeReader = null;
////		 try {
////			 slopeReader = new GeoTiffReader(slopeTifUrl);
////
////			 // 3. 读取栅格元数据（坐标系、空间范围、栅格几何）
////			 GridCoverage2D slopeCoverage = (GridCoverage2D) slopeReader.read(null);
////			 CoordinateReferenceSystem slopeCRS = slopeCoverage.getCoordinateReferenceSystem();
////			 Envelope slopeEnvelope = slopeCoverage.getEnvelope();
////			 GridGeometry2D gridGeometry = slopeCoverage.getGridGeometry();
////
////			 // 4. 经纬度（WGS84）→ 坡度TIF坐标系 转换
////			 CoordinateReferenceSystem wgs84CRS = CRS.decode("EPSG:4326");
////			 MathTransform transform = CRS.findMathTransform(wgs84CRS, slopeCRS, true);
////			 GeometryFactory geometryFactory = new GeometryFactory();
////			 Point wgs84Point = geometryFactory.createPoint(new Coordinate(longitude, latitude));
////			 Point slopePoint = (Point) JTS.transform(wgs84Point, transform);
////			 double x = slopePoint.getX();
////			 double y = slopePoint.getY();
////
////			 // 5. 检查点是否在坡度数据范围内（手动判断坐标范围，兼容无contains方法的Envelope）
////			 double minX = slopeEnvelope.getMinimum(0); // X轴最小值
////			 double maxX = slopeEnvelope.getMaximum(0); // X轴最大值
////			 double minY = slopeEnvelope.getMinimum(1); // Y轴最小值
////			 double maxY = slopeEnvelope.getMaximum(1); // Y轴最大值
////			 if (x < minX || x > maxX || y < minY || y > maxY) {
////				 result.put("status", "fail");
////				 result.put("error", "经纬度点不在坡度数据的空间范围内！\n" +
////						 "当前坐标(x,y): " + x + "," + y + "\n" +
////						 "数据范围(minX,maxX,minY,maxY): " + minX + "," + maxX + "," + minY + "," + maxY);
////				 return result;
////			 }
////
////			 // 6. 计算栅格行列号（含像元中心偏移修正）
////			 AffineTransform gridToCRS = (AffineTransform) gridGeometry.getGridToCRS();
////			 double cellWidth = Math.abs(gridToCRS.getScaleX());   // 像元宽度（X方向分辨率）
////			 double cellHeight = Math.abs(gridToCRS.getScaleY());  // 像元高度（Y方向分辨率）
////
////
////			 // 像元中心偏移：地理坐标转行列号需补偿0.5个像元（GridToCRS以像元中心为原点）
////			 double colDouble = (x - minX) / cellWidth - 0.5;
////			 double rowDouble = (maxY - y) / cellHeight - 0.5;
////			 int col = (int) Math.round(colDouble);
////			 int row = (int) Math.round(rowDouble);
////			 System.out.println("[调试] 计算行列号：col=" + col + ", row=" + row);
////
////			 // 7. 检查行列号是否越界（必开！避免数组越界）
////			 Rectangle gridRange = gridGeometry.getGridRange2D();
////			 System.out.println("[调试] 栅格范围：宽=" + gridRange.width + ", 高=" + gridRange.height);
////			 if (col < 0 || col >= gridRange.width || row < 0 || row >= gridRange.height) {
////				 result.put("status", "fail");
////				 result.put("error", "行列号越界！col=" + col + ", row=" + row + "；栅格宽高：" + gridRange.width + "x" + gridRange.height);
////				 return result;
////			 }
////
////			 // 8. 读取目标像元的坡度值（单波段假设，需与TIF实际波段数一致）
////			 RenderedImage renderedImage = slopeCoverage.getRenderedImage();
////			 Raster raster = renderedImage.getData();
////			 double[] pixelValues = new double[1]; // 单波段数据，数组长度为1
////			 raster.getPixel(col, row, pixelValues);
////			 double slopeValue = pixelValues[0];
////
////			 // 9. 处理NoData无效值（需与TIF元数据一致，示例：-9999）
////			 if (slopeValue == -9999) { // 替换为你TIF的NoData值（QGIS查看图层属性→源→NoData值）
////				 result.put("status", "fail");
////				 result.put("error", "该位置为无效数据（NoData）");
////				 return result;
////			 }
////
////			 result.put("status", "success");
////			 result.put("slope", slopeValue);
////
////		 } catch (FactoryException | TransformException | IOException e) {
////			 result.put("status", "fail");
////			 result.put("error", "处理失败：" + e.getMessage());
////			 e.printStackTrace(); // 控制台打印堆栈，便于调试
////		 } finally {
////			 if (slopeReader != null) {
////				 slopeReader.dispose(); // 释放GeoTiffReader资源
////			 }
////		 }
////
////		 return result;
////	 }
//}
